package Day18;

import java.io.*;
import java.util.*;

public class Main {
    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String, List<String>> hash = new HashMap<>();
        for(String s : strs){
            char[] arr = s.toCharArray();
            Arrays.sort(arr);
            String tmp = new String(arr);
            if(hash.get(tmp) == null){
                hash.put(tmp, new ArrayList<>());

            }
            hash.get(tmp).add(s);

        }
        List<List<String>> ans = new ArrayList<>();
        for(Map.Entry<String, List<String>> e : hash.entrySet()){
            ans.add(e.getValue());
        }
        return ans;
    }
}
